package cn.marinda.listener;

import cn.marinda.entity.ServerProcess;
import cn.marinda.gui.AbstractHelper;
import cn.marinda.util.ServerUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 向服务器发送命令动作事件
 *
 * @author admin
 * @date 2022/07/13
 */
public class SendCommandServerActionEvent implements ActionListener {

    private AbstractHelper helper;

    public SendCommandServerActionEvent(AbstractHelper helper){
        this.helper  = helper;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
//        拿到JTextfield
        JTextField textField = (JTextField) helper.getHelperComponent("TextFieldUI");
        String command = textField.getText();
        ServerProcess.instance.sendCommandToServer(command);
        textField.setText("");
        JTextArea textArea = (JTextArea) helper.getHelperComponent("TextAreaUI");
        textArea.selectAll();
    }

}
